<script setup>
import { ref, computed } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import {
  Document,
  Menu as IconMenu,
  Location,
  Setting,
  ChatLineSquare,
} from '@element-plus/icons-vue'

const router = useRouter()
const route = useRoute()

// 动态计算激活菜单项
const activeIndex = computed(() => {
  const path = route.path
  if (path === '/admin') return '0'
  if (path === '/admin/check') return '1-1'
  if (path === '/admin/report') return '1-2'
  if (path === '/admin/profile') return '2'
  return '0'
})

// 跳转方法需要添加精确路径
const jumpPanel = () => {
  router.push({ path: '/admin', replace: true })
}

const jumpCheck = () => {
  router.push({ path: '/admin/check' })
}

const jumpReport = () => {
  router.push({ path: '/admin/report' })
}

const jumpProfile = () => {
  router.push({ path: '/admin/profile' })
}
</script>

<template>
  <div>
    <el-menu
      :default-active="activeIndex"
      class="el-menu-vertical-demo"
      active-text-color="#409EFF"
      router
    >
      <el-menu-item index="0" @click="jumpPanel" :route="{ path: '/admin' }">
        <el-icon><icon-menu /></el-icon>
        <template #title>管理员仪表盘</template>
      </el-menu-item>

      <el-sub-menu index="1">
        <template #title>
          <el-icon><location /></el-icon>
          <span>管理</span>
        </template>
        <el-menu-item-group>
          <el-menu-item
            index="1-1"
            @click="jumpCheck"
            :route="{ path: '/admin/check' }"
          >
            审核处理
          </el-menu-item>
          <el-menu-item
            index="1-2"
            @click="jumpReport"
            :route="{ path: '/admin/report' }"
          >
            举报处理
          </el-menu-item>
        </el-menu-item-group>
      </el-sub-menu>

      <el-menu-item
        index="2"
        @click="jumpProfile"
        :route="{ path: '/admin/profile' }"
      >
        <el-icon><setting /></el-icon>
        <span>管理资料与密码</span>
      </el-menu-item>
    </el-menu>
  </div>
</template>

<style>
/* 样式 */
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  height: 350px;
  border-radius: 10px;
  margin-left: 120px;
}
</style>
